package convert;

import java.util.ArrayList;

import main.Def;

import org.jdom.Element;

import config.EConfig;

public class ERow extends BaseContent
{
	private int m_start;
	private int m_end;
	
	public ERow(ESheet sheet, int start)
	{
		super(ECell.getValue(sheet.getRealSheet().getRow(start).getCell(0)), sheet);
		m_start = start;
	}
	
	public void setEnd(int end)
	{
		m_end = end;
	}
	
	public int getStart()
	{
		return m_start;
	}
	
	public int getEnd()
	{
		return m_end;
	}
	
	public void init(ArrayList<Head> heads)
	{
		int len = heads.size();
		for(int i = 0; i < len; ++i)
		{
			EColumn cc = new EColumn((ESheet)m_father, heads.get(i).getName(), this); 
			cc.init(heads.get(i));
			addChild(cc);
		}
	}
	
	public void toXml(Element node)
	{
		Element row = null;
		if(EConfig.m_isSimpleFormat)
		{
			row = new Element(m_name);
		}
		else 
		{
			row = new Element(Def.ROW);
			row.setAttribute(Def.NAME, m_name);
		}
		if(m_children != null)
		{
			if(m_children != null)
			{
				for(BaseContent bc: m_children)
				{
					EColumn cc = (EColumn)bc;
					if(!EConfig.m_ignoreCols.containsKey(bc.m_name))
					{
						cc.toXml(row);
					}
				}
			}
		}
		node.addContent(row);
	}
	/*
	public void fromXml(XmlNode node) throws ErrorException
	{
		for(int i = 1, size = node.getChildNumber(); i < size; ++i)
		{
			XmlNode temp = node.getChild(i);
			//String name = temp.getAttribute(Def.VALUE);
		
			EColumn cc = new EColumn(((ESheet)m_father).getSheet(), "", this);
			cc.fromXml(temp, i);
		}
	}*/
}
